#include <bits/stdc++.h>
#define ll long long

using namespace std;
string n;
int main() {
   ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);

   if (fopen("sapxep.inp", "r")){
        freopen("sapxep.inp", "r", stdin);
        freopen("sapxep.out", "w", stdout);
   }
   cin>>n;
   sort(n.begin(),n.end(),greater<char>());
   if(n[3]=='0' || n[3]=='5') cout<<n;
   else{
        int ok=0;
        for(int i=0;i<4;i++)
        if(n[i]=='5'){
            ok=1;
            for(int j=i;j<4;j++)n[j]=n[j+1];
            n[3]='5';
            break;
        }
        if(ok==0) cout<<-1;
        else cout<<n;
   }
    return 0;
}
